package com.zhaoyh.service;

import com.alibaba.druid.util.StringUtils;
import com.zhaoyh.bean.Userinfo;
import com.zhaoyh.mapper.UserinfoMapper;
import org.apache.poi.util.StringUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.UUID;

/**
 * @author 祥霸
 * @date 2019/2/20
 */
@Service
public class UserinfoService {

    @Autowired
    UserinfoMapper userinfoMapper;

    @Autowired
    UserConfigService userConfigService;

    public Userinfo getUserinfo(String username) {
        return userinfoMapper.getUserinfo(username);
    }

    public String getUuid(String account) {
        String uuid = null;
        if (!StringUtils.isEmpty(account)) {
            Userinfo userinfo = this.getUserinfo(account);
            if (userinfo == null) {
                uuid = "";
            } else {
                uuid = userinfo.getUuid();
            }
        }
        return uuid;
    }

    @Transactional
    public String insertUserinfo(String username, String pwd) {
        String uuid = UUID.randomUUID().toString().replace("-", "");
        userinfoMapper.insertUserinfo(username, pwd, "", uuid);

        userConfigService.insertByBatch(uuid);

        return "success";
    }
}
